package org.raymond.iworks.study.basic.designpattern.principle.openclose;

public class OpenClose2 {
    public static void main(String[] args) {
        GraphicEditor1 graphicEditor = new GraphicEditor1();
        graphicEditor.draw(new Circle1());
        graphicEditor.draw(new Rectangle1());
        // 使用方新增代码
        graphicEditor.draw(new Triangle1());
    }
}

// 使用方
class GraphicEditor1 {
    public void draw(Shape1 s){
        s.draw();
    }
}
abstract class Shape1{
    int m_type;
    public abstract void draw();
}
class Rectangle1 extends Shape1{
    Rectangle1(){
        super.m_type=1;
    }

    @Override
    public void draw() {
        System.out.println("1矩形");
    }
}
class Circle1 extends Shape1{
    Circle1(){
        super.m_type=2;
    }
    @Override
    public void draw() {
        System.out.println("1圆形");
    }
}
// 服务方新增代码
class Triangle1 extends Shape1 {
    Triangle1(){
        super.m_type=3;
    }

    @Override
    public void draw() {
        System.out.println("1三角形");
    }
}
